package com.unicom.scg.scancodego.config;


import com.unicom.scg.scancodego.component.LoginHandlerInterceptor;
import com.unicom.scg.scancodego.component.MyLocaleResolver;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.LocaleResolver;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

/**
 * ClassName: MyMvcConfig <br/>
 * Description: <br/>
 * Date: 2019/10/26 11:39<br/>
 *
 * @author jason<br />
 * @version v1.0
 */
@Configuration
public class MyMvcConfig extends WebMvcConfigurerAdapter {


    // ctrl + o 快速查看父类方法和重写父类方法


    // 配置自己的视图解析器
    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        super.addViewControllers(registry);


        registry.addViewController("/userAdmin").setViewName("userAdmin");
        // ......
    }

    @Bean
    public LocaleResolver localeResolver(){
        return new MyLocaleResolver();
    }

    //添加拦截器
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        super.addInterceptors(registry);

//        registry.addInterceptor(new LoginHandlerInterceptor())
//                .addPathPatterns("/**") // 拦截所有请求
 //               .excludePathPatterns("/login","/user/login"); // 排除拦截的请求
//        registry.addInterceptor();
//        registry.addInterceptor();

    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
//        super.addResourceHandlers(registry);
        registry.addResourceHandler("/upLoad/**")
                .addResourceLocations("file:D:/upLoad/");
    }
}
